$(function (){
    $.get(
        "queryCategory",
        function (resp){
            let cats=resp.data;
            //循环父类
            for (let i = 0; i < cats.length; i++) {
                //得到父类
                let parent=cats[i];
                let tr=$(`<li class="dropdown breadcrumb-item">
                                    <a href="products.html" class="dropdown-toggle" data-toggle="dropdown">${parent.name}</a>
                                    <ul class="dropdown-menu">
                                        <li class="dropdown-item">
                                            <a href="products.html">全部</a>
                                        </li>
                                        <li class="dropdown-divider"></li>
                                    </ul>
                                </li>`);
                //循环儿子
                let sons=parent.sons;
                for (let j = 0; j < sons.length; j++) {
                    let str=$(`<li class="dropdown-item">
                                            <a href="products.html?sid=${sons[j].id}">${sons[j].name}</a>
                                        </li>`);
                    tr.find("ul").append(str);
                }
                $("#ul-div").append(tr);
            }
        },
        "json"
    );
})